package com.hook3.pianke.Adapter;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.hook3.pianke.R;
import com.hook3.pianke.domain.RadioInfo;

import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.ArrayList;

/**
 * Created by HOME on 2015/12/9.
 */
public class RadioGridViewAdapter extends BaseAdapter {

    private ArrayList<RadioInfo.RadioHotlist> radioHotlists;
    private Activity activity;
    public RadioGridViewAdapter(ArrayList<RadioInfo.RadioHotlist> radioHotlists, Activity activity){
        this.radioHotlists = radioHotlists;
        this.activity = activity;
    }

    @Override
    public int getCount() {
        return radioHotlists.size();
    }

    @Override
    public RadioInfo.RadioHotlist getItem(int position) {
        return radioHotlists.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = View.inflate(activity, R.layout.item_radio_grad,null);
            holder.image = (ImageView) convertView.findViewById(R.id.iv_radio_grad_image);
            holder.iconNew = (ImageView) convertView.findViewById(R.id.iv_radio_grad_new);

            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }

        RadioInfo.RadioHotlist radioHotInfo = getItem(position);

        //设置广播图片
        ImageOptions imageOptions = new ImageOptions.Builder().build();
        x.image().bind(holder.image,radioHotInfo.coverimg,imageOptions);

        //设置new图片
        if(radioHotInfo.isnew){
            holder.iconNew.setVisibility(View.VISIBLE);
        }else{
            holder.iconNew.setVisibility(View.INVISIBLE);
        }

        return convertView ;
    }

    static class ViewHolder {
        ImageView image;
        ImageView iconNew;
    }
}
